/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package asteroidmining1;

/**
 *
 * @author IVAN
 */
public class Collision {

    private double _width, _height;

    public boolean CollisionBetweenBallAndAtmosfere(CannonBall ball, Asteroid asteroid) {
        return (((double) (ball.radius() + asteroid.radiusGravity())) >= (Math.sqrt(Math.pow((double) (ball.x() - asteroid.x()), (double) 2.0) + Math.pow((double) (ball.y() - asteroid.y()), 2.0))));
    }

    public boolean CollisionBetweenBallAndAsteroid(CannonBall ball, Asteroid asteroid) {
        return (((double) (ball.radius() + asteroid.radius())) >= (Math.sqrt(Math.pow((double) (ball.x() - asteroid.x()), (double) 2.0) + Math.pow((double) (ball.y() - asteroid.y()), 2.0))));
    }

    boolean BallOutOfCenario(CannonBall cannonBall) {
        return ((cannonBall.x() + cannonBall.radius()) <= 0 || (cannonBall.x() - cannonBall.radius()) >= getWidth() || (cannonBall.y() + cannonBall.radius()) <= 0 || (cannonBall.y() - cannonBall.radius()) >= getHeight());
    }

    /**
     * @return the _width
     */
    public double getWidth() {
        return _width;
    }

    /**
     * @param width the _width to set
     */
    public void setWidth(double width) {
        this._width = width;
    }

    /**
     * @return the _height
     */
    public double getHeight() {
        return _height;
    }

    /**
     * @param height the _height to set
     */
    public void setHeight(double height) {
        this._height = height;
    }

    void EnterInGravityField(CannonBall ball, Asteroid asteroid) {
                
        if (ball.x() < asteroid.x() && ball.y() < asteroid.y()) {
            ball.Quadrante = 2;
        }
        if (ball.x() > asteroid.x() && ball.y() < asteroid.y()) {
            ball.Quadrante = 1;
        }
        if (ball.x() < asteroid.x() && ball.y() > asteroid.y()) {
            ball.Quadrante = 3;
        }
        if (ball.x() > asteroid.x() && ball.y() > asteroid.y()) {
            ball.Quadrante = 4;
        }
        
        if (ball.x() < asteroid.x() && ball.y() == asteroid.y()) {
            ball.Quadrante = 6;
        }
        if (ball.x() > asteroid.x() && ball.y() == asteroid.y()) {
            ball.Quadrante = 5;
        }
        if (ball.x() == asteroid.x() && ball.y() > asteroid.y()) {
            ball.Quadrante = 7;
        }
        if (ball.x() == asteroid.x() && ball.y() > asteroid.y()) {
            ball.Quadrante = 8;
        }
        
    }

    public void GravityPower(CannonBall ball, Asteroid asteroid) {
        ball.GRAVITY_EFFECT = (10*(asteroid.getM())/ Math.pow( Distancia(ball, asteroid), 1.07 ));
    }
    
    private double Distancia(CannonBall ball, Asteroid asteroid) {
        double distancia = 0;
        
        distancia = (Math.sqrt(Math.pow((double) (ball.x() - asteroid.x()), (double) 2.0) + Math.pow((double) (ball.y() - asteroid.y()), 2.0)));
        
        return distancia;
    }
   
}
